// 1. 绘制LSA图示例examples
// create an array with nodes
// import vis from "vis";
import vis from 'vis'
export function useDraw() {
  /**@param {*}
   * 绘制LSA图
   *
   */
  let vis_network = null;
  function handleDrawLsa(container, options, nodes, edges) {
    nodes = new vis.DataSet(nodes);
    edges = new vis.DataSet(edges);
    let data = {
      nodes: nodes,
      edges: edges,
    };
    if (vis_network) {
      vis_network.destroy();
    }
    // console.log('options=', options)
    vis_network = new vis.Network(container, data, options);
    return vis_network;
  }

  function getInfoOfLine(network) {
    // 将线段的节点信息返回
    if(network.getSelectedEdges().length === 0){
      return false
    }
    let from = network.body.edges[network.getSelectedEdges()[0]].options.from
    let to = network.body.edges[network.getSelectedEdges()[0]].options.to
    return { from, to }
  }
  return {
    handleDrawLsa,
    getInfoOfLine
  };
}
